import request from '../../utils/request'
import { CHANNEL_ACTIVE, CHANNEL_SAVE } from '../constants'

export const getChannelAc = (channels) => ({
  type: CHANNEL_SAVE,
  channels,
})

export const getChannel = () => {
  // 这个是 redux-thunk 中间所支持的
  return async (dispatch) => {
    // 【获取数据】
    const {
      data: {
        data: { channels },
      },
    } = await request.get('/channels')
    // 【存储到 Redux】=> dispatch(action)
    dispatch(getChannelAc(channels))
  }
}

export const changeActive = (channelId) => ({
  type: CHANNEL_ACTIVE,
  active: channelId,
})
